home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / RNDGEN10 / MD2P31.ASM next >
Assembly Source File  |  1993-12-06  |  1KB  |  62 lines

  1. ; MD2P31.ASM, for Turbo Assembler
  2.  
  3.           .MODEL TPASCAL    ; 16-bit segments
  4.           .386C             ; non-privileged 386 instructions
  5.  
  6. CODE      SEGMENT BYTE PUBLIC
  7.           ASSUME cs:CODE,ds:NOTHING
  8.  
  9. ; PASCAL declaration
  10. ;   PROCEDURE MD2P31 (A,B : longint;
  11. ;                     VAR Q,R : longint); far; external;
  12.  
  13. ; calculate product a*b, represent product as q*2^31+r, 0<=r<2^31
  14. ; return q and r
  15.  
  16. ; Parameters (+2 because of push bp)
  17.  
  18. R         EQU DWORD PTR ss:[bp+6]
  19. Q         EQU DWORD PTR ss:[bp+10]
  20. B         EQU DWORD PTR ss:[bp+14]
  21. A         EQU DWORD PTR ss:[bp+18]
  22.  
  23.  
  24. MD2P31    PROC FAR
  25.           PUBLIC MD2P31
  26.  
  27.           push  bp
  28.           mov   bp,sp          ;get pointer into stack
  29.           push  es
  30.           push  di             ;manual says we don't need to save
  31.           push  eax            ;those registers, but safety first!
  32.           push  ebx
  33.           push  edx
  34.  
  35.           mov   eax,a
  36.           mov   ebx,b
  37.           imul  ebx            ; a*b in edx:eax
  38.  
  39.           mov   ebx,eax
  40.           SHLD  edx,ebx,1      ; edx contains q
  41.  
  42.           and   eax,07fffffffh ; eax contains r
  43.           les   di,r
  44.           stosd
  45.  
  46.           mov   eax,edx
  47.           les   di,q
  48.           stosd
  49.  
  50.           pop   edx
  51.           pop   ebx
  52.           pop   eax
  53.           pop   di
  54.           pop   es
  55.           pop   bp
  56.           retf  16             ;parameters take 16 bytes
  57. MD2P31    ENDP
  58.  
  59. CODE      ENDS
  60.  
  61.           END
  62.